package com.shiwaixiangcun.monitor.controller;

import com.shiwaixiangcun.core.plugin.dto.MonkeyDto;
import com.shiwaixiangcun.core.plugin.web.validator.ConstraintType;
import com.shiwaixiangcun.core.plugin.web.validator.ParameterConstraint;
import com.shiwaixiangcun.core.plugin.web.validator.ParameterConstraints;
import com.shiwaixiangcun.monitor.dto.TimeOutDateDto;
import com.shiwaixiangcun.monitor.dto.WorkOrderTimeoutRuleDto;
import com.shiwaixiangcun.monitor.service.WorkOrderTimeoutRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * Created by Administrator on 2017/11/23.
 */
@Controller
@RequestMapping("/work/order/timeout")
public class WorkOrderTimeoutRuleController {

    @Autowired
    private WorkOrderTimeoutRuleService workOrderTimeoutRuleService;

    @RequestMapping(value = "/listdata", method = RequestMethod.GET)
    public List<WorkOrderTimeoutRuleDto> listData() {
        return workOrderTimeoutRuleService.ruleList();
    }


    @RequestMapping(value = "/date", method = RequestMethod.GET)
    public List<TimeOutDateDto> getDateList() {
        return workOrderTimeoutRuleService.getTimeOutDateList();
    }


    @ParameterConstraints({
            @ParameterConstraint(name = "categoryId", constraintType = {ConstraintType.NotNull}, notNull = @NotNull(message = "工单分类不能为空")),
            @ParameterConstraint(name = "time", constraintType = {ConstraintType.NotNull}, notNull = @NotNull(message = "超时时间不能为空")),
            @ParameterConstraint(name = "userId", constraintType = {ConstraintType.NotNull}, notNull = @NotNull(message = "提醒人不能为空"))
    })
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public String add(MonkeyDto monkeyDto) {
        workOrderTimeoutRuleService.ruleAdd(monkeyDto);
        return "SUCCESS:添加成功";
    }

    @RequestMapping(value = "/remove", method = RequestMethod.DELETE)
    public String remove(@RequestParam Long id) {
        workOrderTimeoutRuleService.ruleRemove(id);
        return "SUCCESS:已成功移除";
    }

    @RequestMapping("/ts")
    public void ts() {
        workOrderTimeoutRuleService.execTimeOutJob();
    }

}
